<?php
	class hinhthucvaydb
	{
		public function Them($TenHinhThucVay = "", $LaiSuatVay = 0)
		{
			$sql = "INSERT INTO hinhthucvay(TenHinhThucVay, LaiSuatVay)
						   VALUES('$TenHinhThucVay', $LaiSuatVay)";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaHinhThucVay = 0, $TenHinhThucVay = "", $LaiSuatVay = 0)
		{
			$sql = "UPDATE hinhthucvay 
					SET TenHinhThucVay = '$TenHinhThucVay',
						LaiSuatVay = $LaiSuatVay
					WHERE MaHinhThucVay = $MaHinhThucVay";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		

		public function TonTaiTrongKyHanTra($MaHinhThucVay = 0)
		{
			$sql = "SELECT * FROM kyhantra WHERE 1";
			if($MaHinhThucVay > 0)
				$sql.= " AND MaHinhThucVay = $MaHinhThucVay";
		
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function Xoa($MaHinhThucVay = 0)
		{
			$sql = "DELETE FROM hinhthucvay 
					WHERE MaHinhThucVay = $MaHinhThucVay";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM hinhthucvay";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaHinhThucVay = 0, $TenHinhThucVay = "", $LaiSuatVay = 0)
		{
			$sql = "SELECT * 
					FROM hinhthucvay 
					WHERE 1";
			
			if($MaHinhThucVay > 0)
				$sql .= " AND MaHinhThucVay = $MaHinhThucVay";
				
			if($TenHinhThucVay != "")
				$sql .= " AND TenHinhThucVay = '$TenHinhThucVay'";
			
			if($LaiSuatVay > 0)
				$sql .= " AND LaiSuatVay = $LaiSuatVay";
				
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>